package com.ll.studentservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ll.commonUtils.R;
import com.ll.studentservice.entity.EduStartWeek;
import com.ll.studentservice.service.EduStartWeekService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ll
 * @since 2020-12-07
 */
@Api(description = "周数获取API") //swagger界面提示
@RestController
@RequestMapping("/studentservice/edustartweek")
public class EduStartWeekController {

    @Autowired
    private EduStartWeekService eduStartWeekService;

    //添加
    @ApiOperation(value = "添加信息") //swagger界面提示
    @PostMapping("addStartDateInfo")
    public R addStartDateInfo(@RequestBody EduStartWeek eduStartWeek){
        //年份区间
        String year = eduStartWeek.getYear();

        //第几学期
        String semester = eduStartWeek.getSemester();

        //学期开始时间
        String semesterStart = eduStartWeek.getSemesterStart();

        //学期结束时间
        String semesterEnd = eduStartWeek.getSemesterEnd();

        //描述
        String info = eduStartWeek.getInfo();

        EduStartWeek startWeek = new EduStartWeek();

        startWeek.setYear(year);
        startWeek.setSemester(semester);
        startWeek.setSemesterStart(semesterStart);
        startWeek.setSemesterEnd(semesterEnd);
        startWeek.setInfo(info);

        boolean save = eduStartWeekService.save(startWeek);

        return save ? R.ok().message("添加成功") : R.error().message("添加失败");
    }

    //获取现在是第几周
    @ApiOperation(value = "获取现在是第几周") //swagger界面提示
    @PostMapping("getNowWeek")
    public R getNowWeek(){
        String nowWeek = eduStartWeekService.getNowWeek();
        return R.ok().data("nowWeek",nowWeek);
    }
}

